<template>
    <nut-tabbar v-if="createBy != 'user'" unactive-color="#7d7e80" active-color="#4985F2" v-model="activeName"
        @tab-switch="tabSwitch" bottom safe-area-inset-bottom placeholder>
        <nut-tabbar-item v-for="(item, index) in List" :name="item.name" :tab-title="item.title" :icon="item.icon">
        </nut-tabbar-item>
    </nut-tabbar>
    <nut-tabbar v-if="createBy == 'user'" unactive-color="#7d7e80" active-color="#4985F2" v-model="activeName"
        @tab-switch="tabSwitch" bottom safe-area-inset-bottom placeholder>
        <nut-tabbar-item v-for="(item, index) in menu" :name="item.name" :tab-title="item.title" :icon="item.icon">
        </nut-tabbar-item>
    </nut-tabbar>
</template>

<script>
import Taro, { useRouter } from '@tarojs/taro'
import { reactive, onMounted, onLoad } from 'vue';
import { h, ref } from 'vue';
import { Order, Scan, Uploader, Shop3, Setting } from '@nutui/icons-vue-taro';
export default {
    components: { Order, Scan, Uploader, Shop3, Setting },
    setup() {
        onMounted(() => {
            const router = useRouter();
            if (router.params.name) {
                activeName.value = router.params.name
            }
            Taro.getStorage({
                key: 'user',
                success: function (res) {
                    if (res.data.createBy) {
                        createBy.value = res.data.createBy
                    }
                }
            })
        })
        const createBy = ref('');
        const activeName = ref(Taro.getCurrentInstance().router.params.name || 'indexPage');
        const menu = [
            {
                title: '订单处理',
                icon: h(Order),
                pagePath: 'pages/index/index',
                name: 'indexPage'
            },
            {
                title: '设置',
                icon: h(Setting),
                pagePath: 'pages/mypage/index',
                name: 'myPage'
            }
        ]
        const List = [
            {
                title: '订单处理',
                icon: h(Order),
                pagePath: 'pages/index/index',
                name: 'indexPage'
            },
            {
                title: '订单查询',
                icon: h(Scan),
                pagePath: 'pages/shoppage/index',
                name: 'shopPage'
            },
            {
                title: '店铺管理',
                icon: h(Shop3),
                pagePath: 'pages/cartpage/index',
                name: 'cartPage'
            },
            {
                title: '设置',
                icon: h(Setting),
                pagePath: 'pages/mypage/index',
                name: 'myPage'
            }
        ]
        function tabSwitch(item, index) {
            switch (index) {
                case 'indexPage':
                    Taro.reLaunch({ url: '/pages/index/index?name=indexPage' });
                    break;
                case 'shopPage':
                    Taro.reLaunch({ url: '/pages/shoppage/index?name=shopPage' });
                    break;
                case 'cartPage':
                    Taro.reLaunch({ url: '/pages/cartpage/index?name=cartPage' });
                    break;
                case 'myPage':
                    Taro.reLaunch({ url: '/pages/mypage/index?name=myPage' });
                    break;
                default:
                    break;
            }
        }
        return {
            tabSwitch,
            List,
            menu,
            activeName,
            createBy,
        };
    },
}
</script>

<style></style>